<template>
	<view class="all">
		<view class="top">
			<view class="jifen">绿色积分</view>
			<view class="jifen" @click="record">操作记录</view>
		</view>
		<view class="list">
			<view class="list_top"> 提现数额 </view>
			<view class="list_box">
				<input :placeholder="placeholder" type="number" :value="shue" class="list_box_input" @input="input_tap"/>
				<view class="list_box_text" @click="all_tap"> | 全部 </view>
			</view>
		</view>
		<view class="list">
			<view class="list_top" style="display: flex;justify-content: space-between;" >  
				<view>{{bank.bank}}</view>
				<view style="border: 1upx solid #ff0000;padding: 10upx;font-size: 28upx;color: #ff0000;font-weight: 400;" v-if="bank_key == false" @click="add_bank"> 添加银行卡 </view>
			</view>
			<view class="list_box">
				<input :placeholder="bank.bank" disabled type="number" :value="bank.bank" class="list_box_input" />
			</view>
		</view>
		<view class="list">
			<view class="list_box">
				<input :placeholder="bank.bank_address" disabled type="number" :value="bank.bank_address" class="list_box_input" />
			</view>
		</view>
		<view class="list">
			<view class="list_box">
				<input :placeholder="bank.bank_card" disabled type="number" :value="bank.bank_card" class="list_box_input" />
			</view>
		</view>
		<view class="list">
			<view class="list_box">
				<input :placeholder="bank.bank_name" disabled type="number" :value="bank.bank_name" class="list_box_input" />
			</view>
		</view>
		<view class="list">
			<view class="list_top"> 交易密码 </view>
			<view class="list_box">
				<input placeholder="请输入交易密码" type="number" class="list_box_input" @input="password_tap"/>
			</view>
		</view>
		<view class="tishi">
			温馨提示：转出前请务必确认账户信息无误，已经转出则不可撤销，请仔细核对。
		</view>
		<view class="queren">
			<view :class="queren_key == 1?'queren_texts':'queren_text'" @click="user_withdraw_api"> 确认提现 </view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				placeholder:'可提现0积分',
				shue:'',
				password:'',
				queren_key:0,
				money:0,
				moneys:'',
				bank:{},
				bank_key:false,
				money_data:0
			}
		},
		onShow() {
			this.user_assets_api()
			this.list_api()
			this.user_withdrawss_api()
		},
		methods: {
			user_withdrawss_api() {
				var that = this
				that.$request(that.$Api.user_withdrawss_api, {
					access_token: uni.getStorageSync('access_token'),
				}, "POST").then(res => {
					if (res.data.code == 0) {
						that.money_data = Number(res.data.data.text)
					} else {
						uni.showToast({
							title: res.data.msg,
							duration: 2000,
							icon: 'none'
						});
					}
				})
			},
			add_bank() {
				uni.navigateTo({
					url:'../set/set'
				})
			},
			list_api() {
				var that = this
				that.$request(that.$Api.user_person_api, {
					access_token: uni.getStorageSync('access_token'),
				}, "POST").then(res => {
					if (res.data.code == 0) {
						if( res.data.data.list.bank == '' || res.data.data.list.bank == null ) {
							that.bank_key = false
							that.bank = {
								bank:'开户银行',
								bank_address:'银行支行',
								bank_card:'银行卡号',
								bank_name:'银行卡户名',
							}
						}else{
							that.bank_key =true
							that.bank = res.data.data.list
						}
						console.log('that.bank',that.bank)
					} else {
						uni.showToast({
							title: res.data.msg,
							duration: 2000,
							icon: 'none'
						});
					}
				})
			},
			all_tap() {
				this.shue = this.money
				this.queren_key_tap()
			},
			//首页
			user_assets_api() {
				var that = this
				that.$request(that.$Api.user_assets_api, {
					access_token: uni.getStorageSync('access_token'),
				}, "POST").then(res => {
					if (res.data.code == 0) {
						that.money = res.data.data.money
						that.placeholder = '可提现'+that.money+'积分'
					} else {
						uni.showToast({
							title: res.data.msg,
							duration: 2000,
							icon: 'none'
						});
					}
				})
			},
			user_withdraw_api() {
				var that = this
				if( that.queren_key == 0 ) {
					return
				}
				if( that.money_data > that.shue ) {
					uni.showToast({
						title: '不可低于'+that.money_data,
						duration: 2000,
						icon: 'none'
					});
					return
				}
				let a = that.shue % 100;
				console.log('a',a)
				if(a != 0) {
					uni.showToast({
						title: '请输入100的倍数，进行提现',
						duration: 2000,
						icon: 'none'
					});
					return
				}
				that.$request(that.$Api.user_withdraw_api, {
					access_token: uni.getStorageSync('access_token'),
					money:that.shue,
					password:that.password
				}, "POST").then(res => {
					if (res.data.code == 0) {
						that.user_assets_api()
						uni.showToast({
							title: res.data.msg,
							duration: 2000,
							icon: 'none'
						});
						setTimeout(function () {
							uni.navigateBack()
						}, 2000);
					} else {
						uni.showToast({
							title: res.data.msg,
							duration: 2000,
							icon: 'none'
						});
					}
				})
			},
			record() {
				uni.navigateTo({
					url:'../record/record'
				})
			},
			input_tap(num) {
				this.shue = num.detail.value
				this.queren_key_tap()
			},
			password_tap(num) {
				this.password = num.detail.value
				this.queren_key_tap()
			},
			queren_key_tap() {
				if( this.shue != '' && this.password != '' ) {
					this.queren_key = 1
				}else{
					this.queren_key = 0
				}
			},
		}
	}
</script>

<style lang="less">
	page{
		.all{
			.queren{
				.queren_text{
					width: 700upx;
					border-radius: 20upx;
					text-align: center;
					line-height: 80upx;
					height: 80upx;
					background: #999;
					color: #fff;
					margin-left: 25upx;
				}
				.queren_texts{
					width: 700upx;
					border-radius: 20upx;
					text-align: center;
					line-height: 80upx;
					height: 80upx;
					background: #ff0000;
					color: #fff;
					margin-left: 25upx;
				}
				width: 750upx;
				padding: 10upx 0;
				background: #fff;
				position: fixed;
				bottom: 0;
				z-index: 2;
			}
			.tishi{
				width: 700upx;
				font-size: 22upx;
				padding: 25upx 25upx 130upx 25upx;
				color: #999;
			}
			.list{
				.list_box{
					.list_box_text{
						font-size: 28upx;
						color: #333;
						margin-top: 4upx;
					}
					.list_box_input{
						width: 500upx;
						font-size: 28upx;
						color: #333;
					}
					display: flex;
					justify-content: space-between;
					margin-top: 20upx;
					background: #eee;
					padding: 15upx;
					width: 670upx;
				}
				.list_top{
					font-size: 36upx;
					font-weight: bold;
				}
				width: 700upx;
				padding: 25upx;
			}
			.top{
				.jifen{
					font-size: 28upx;
					color: #999;
				}
				display: flex;
				width: 700upx;
				padding: 25upx;
				justify-content: space-between;
			}
		}
	}
</style>
